package edu.ucsc.mit2008.swan.editor.coreUI.internal.views;

import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.part.ViewPart;

public class PropertiesView extends ViewPart {

	public static final String PROPERTIES_VIEW_ID = "edu.ucsc.mit2008.swan.coreUI.propertiesView";
	
	private Label nameLabel;
	private Text nameText;
	
	private Label imagesFolderLabel;
	private Text imagesFolderText;
	private Button imagesFolderButton;
	
	private Composite propertiesContainer;
	
	public PropertiesView() {
		
	}

	@Override
	public void createPartControl(Composite parent) {
		GridLayoutFactory.fillDefaults().numColumns(1).equalWidth(false).applyTo(parent);
		Group group = new Group(parent, SWT.BORDER);
		GridDataFactory.fillDefaults().align(SWT.FILL, SWT.TOP).grab(true, false).applyTo(group);
		GridLayoutFactory.fillDefaults().numColumns(3).equalWidth(false).applyTo(group);
		nameLabel = new Label(group, SWT.NONE);
		nameLabel.setText("Name");
		GridDataFactory.fillDefaults().applyTo(nameLabel);
		nameText = new Text(group, SWT.BORDER);
		GridDataFactory.fillDefaults().align(SWT.FILL, SWT.TOP).grab(true, false).span(2, SWT.DEFAULT).applyTo(nameText);		
		
		imagesFolderLabel = new Label(group, SWT.NONE);
		imagesFolderLabel.setText("Images folder");
		GridDataFactory.fillDefaults().applyTo(imagesFolderLabel);
		imagesFolderText = new Text(group, SWT.BORDER);
		GridDataFactory.fillDefaults().align(SWT.FILL, SWT.TOP).grab(true, false).applyTo(imagesFolderText);
		imagesFolderButton = new Button(group, SWT.PUSH);
		imagesFolderButton.setText("Browse");
		GridDataFactory.fillDefaults().align(SWT.FILL, SWT.TOP).applyTo(imagesFolderButton);
		imagesFolderButton.addSelectionListener(new SelectionAdapter() {

			@Override
			public void widgetSelected(SelectionEvent e) {
				FileDialog dialog = new FileDialog(Display.getDefault().getActiveShell(), SWT.OPEN);
				dialog.setFilterExtensions(new String[] {"*"});
				String file = dialog.open();
				imagesFolderText.setText(file == null ? "" : file);
			}
			
		});
		
		propertiesContainer = new  Composite(parent, SWT.BORDER);
		GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(propertiesContainer);
	}

	@Override
	public void setFocus() {
		// TODO Auto-generated method stub

	}

}
